package com.example.blog.mapper;

/**
 * ClassName: BlogMapper
 * Package: IntelliJ IDEA
 * Description:
 *
 * @Author 谷京京
 * @Create 2024/3/26 8:58
 * @Version 1.0
 */

import com.example.blog.model.BlogInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 用户登录, 根据用户名查询用户信息
 * 博客列表页, 根据用户id, 查询用户信息
 */
@Mapper
public interface BlogMapper {
    /**
     * 获取博客列表
     */
    @Select("select * from blog where delete_flag = 0 order by create_time desc ")
    List<BlogInfo> queryBlogList();
    /**
     * 根据博客id, 获取博客详情
     */
    @Select("select * from blog where id = #{blogId}")
    BlogInfo queryById(Integer blogId);
    /**
     * 编辑
     */
    @Update("update blog set title = #{title}, content = #{content} where id = #{id}")
    Integer update(BlogInfo blogInfo);
    /**
     * 删除
     */
    @Update("update blog set delete_flag = 1 where id = #{blogId}")
    Integer delete(Integer blogId);
    /**
     * 添加博客
     */
    @Insert("insert into blog(title, content, user_id) values (#{title}, #{content}, #{userId})")
    Integer insertBlog(BlogInfo blogInfo);

}
